/
ViewAllUser.js
executable file
·60 lines (56 loc) · 1.73 KB
/
ViewAllUser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*Screen to view all the user*/
import React from 'react';
import { FlatList, Text, View } from 'react-native';
import { openDatabase } from 'react-native-sqlite-storage';
import Mybutton from './components/Mybutton';
var db = openDatabase({ name: 'amplisync.db' });
export default class ViewAllUser extends React.Component {
constructor(props) {
super(props);
this.state = {
FlatListItems: [],
};
}
ListViewItemSeparator = () => {
return (
<View style={{ height: 0.2, width: '100%', backgroundColor: '#808080' }} />
);
};
render() {
db.transaction(tx => {
tx.executeSql('SELECT * FROM Users', [], (tx, results) => {
var temp = [];
for (let i = 0; i < results.rows.length; ++i) {
temp.push(results.rows.item(i));
console.log(results.rows.item(i));
}
this.setState({
FlatListItems: temp,
});
});
});
return (
<View>
<Mybutton
title="Add new user"
customClick={() => this.props.navigation.navigate('AddNewUser')}
/>
<FlatList
data={this.state.FlatListItems}
ItemSeparatorComponent={this.ListViewItemSeparator}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => (
<View key={item.usrId} style={{ backgroundColor: 'white', padding: 20 }}>
<Text>Id: {item.usrId}</Text>
<Text>Name: {item.usrName}</Text>
<Text>Last Name: {item.usrLastName}</Text>
<Text>Age: {item.usrAge}</Text>
<Text>Login: {item.usrLogin}</Text>
<Text>Password: {item.usrPass}</Text>
</View>
)}
/>
</View>
);
}
}